package me.dz.dreamcleaner.listener;

import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.inventory.EquipmentSlot;

import java.util.HashMap;

import static me.dz.dreamcleaner.utils.MsgUtils.*;
import static me.dz.dreamcleaner.DreamCleaner.*;

public class RightEvent implements Listener {

    public static HashMap<String,Boolean> bMap = new HashMap<>();

    @EventHandler
    public void onRight(PlayerInteractEntityEvent e){
        boolean b = bMap.getOrDefault(e.getPlayer().getName(),false);
        if (offhand)if (e.getHand() == EquipmentSlot.OFF_HAND)return;
        if (b){
            Entity entity = e.getRightClicked();
            String name = entity.getType().name();
            String msg = "&e右键的实体类型:&b " + name;
            try {
                TextComponent text = new TextComponent();
                text.setText(prefix + format(msg));
                try {
                    text.setClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD,name));
                }catch (NoSuchFieldError ignored){
                    text.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL,"https://"+name+".com/"));
                }
                text.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
                        TextComponent.fromLegacyText(format("&a点击我复制实体类型名字\n&b"+name))));
                e.getPlayer().spigot().sendMessage(text);
            }catch (NoSuchMethodError ignored){
                chat(e.getPlayer(),msg);
            }
        }
    }
}
